package com.fjec.paid.schedule;

import com.fjec.paid.schedule.handler.DivideHandler;
import com.fjec.paid.schedule.handler.QueryDivideHandler;
import com.fjec.paid.schedule.handler.QueryRefundHandler;
import com.fjec.paid.schedule.handler.RefundHandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class PaidSchedule {

    @Autowired
    private RefundHandler refundHandler;

    @Autowired
    private DivideHandler divideHandler;

    @Autowired
    private QueryDivideHandler queryDivideHandler;

    @Autowired
    private QueryRefundHandler queryRefundHandler;

    /**
     * 补偿退款定时任务
     * @param param
     * @return
     */
    @XxlJob("refundHandler")
    public ReturnT<String> refundHandler(String param) {
        String[] args = param.split(",");
        int limit = Integer.valueOf(args[0]).intValue();
        int minutes = Integer.valueOf(args[1]).intValue();
        refundHandler.handle(limit, minutes);

        ReturnT<String> returnT = ReturnT.SUCCESS;
        returnT.setContent("refundHandler");
        return returnT;
    }

    /**
     * 分账定时任务
     * @param param
     * @return
     */
    @XxlJob("divideHandler")
    public ReturnT<String> divideHandler(String param) {
        String[] args = param.split(",");
        int limit = Integer.valueOf(args[0]).intValue();
        int minutes = Integer.valueOf(args[1]).intValue();
        divideHandler.handle(limit, minutes);

        ReturnT<String> returnT = ReturnT.SUCCESS;
        returnT.setContent("divideHandler");
        return returnT;
    }

    @XxlJob("queryDivideHandler")
    public ReturnT<String> queryDivideHandler(String param) {
        String[] args = param.split(",");
        int limit = Integer.valueOf(args[0]).intValue();
        int minutes = Integer.valueOf(args[1]).intValue();
        queryDivideHandler.handle(limit, minutes);

        ReturnT<String> returnT = ReturnT.SUCCESS;
        returnT.setContent("queryDivideHandler");
        return returnT;
    }

    @XxlJob("queryRefundHandler")
    public ReturnT<String> queryRefundHandler(String param) {
        String[] args = param.split(",");
        int limit = Integer.valueOf(args[0]).intValue();
        int minutes = Integer.valueOf(args[1]).intValue();
        queryRefundHandler.handle(limit, minutes);

        ReturnT<String> returnT = ReturnT.SUCCESS;
        returnT.setContent("queryDivideHandler");
        return returnT;
    }
}
